package com.lingyun.mqttserver.controller;

import com.lingyun.mqttserver.dao.pojo.DeviceType;
import com.lingyun.mqttserver.dao.pojo.DeviceTypeVariableTemplate;
import com.lingyun.mqttserver.service.ManageDataService;
import com.lingyun.mqttserver.vo.DeviceTypeVariableTemplateVo;
import com.lingyun.mqttserver.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

// 设备类型管理
@RestController
@RequestMapping("device-type")
public class DeviceTypeController {

    @Autowired
    private ManageDataService manageDataService;

    /**
     * 根据条件列表查询
     * @param projectId  项目ID（可选，用于筛选特定项目下的设备类型）
     * @param keyword    搜索关键词（可选，用于模糊搜索类型名称）
     * @param page       页码（可选，默认1）
     * @param pageSize   每页大小（可选，默认10）
     * @return
     */
    @GetMapping("deviceTypeList")
    public Result deviceTypeList(@RequestParam(required = false) Integer projectId, @RequestParam(required = false) String keyword, @RequestParam(required = false, defaultValue = "1") Integer page, @RequestParam(required = false, defaultValue = "10") Integer pageSize) {
        return manageDataService.deviceTypeList(projectId, keyword, page, pageSize);
    }

    // 通过项目id查询
    @GetMapping("deviceTypeListAll")
    public Result deviceTypeListAll(Integer projectId){
        return manageDataService.deviceTypeListAll(projectId);
    }

    // 增加
    @PostMapping("deviceTypeAdd")
    public Result deviceTypeAdd(@RequestBody DeviceType deviceType){
        return manageDataService.deviceTypeAdd(deviceType);
    }

    // 更新
    @PostMapping("deviceTypeUpdate")
    public Result deviceTypeUpdate(@RequestBody DeviceType deviceType){
        return manageDataService.deviceTypeUpdate(deviceType);
    }

    // 删除
    @DeleteMapping("deviceTypeDelete")
    public Result deviceTypeDelete(@RequestParam Integer id){
        return manageDataService.deviceTypeDelete(id);
    }

    // 通过项目更新
    @GetMapping("deviceTypeByProject")
    public Result deviceTypeByProject(@RequestParam Integer projectId){
        return manageDataService.deviceTypeByProject(projectId);
    }


    /********下面是变量相关的********/

    @GetMapping("variableList")
    public Result variableList(@RequestParam Integer deviceTypeId){
        return manageDataService.variableList(deviceTypeId);
    }

    @PostMapping("variableAdd")
    public Result variableAdd(@RequestBody DeviceTypeVariableTemplateVo deviceTypeVariableTemplateVo){
        return manageDataService.variableAdd(deviceTypeVariableTemplateVo);
    }

    @PostMapping("variableUpdate")
    public Result variableUpdate(@RequestBody DeviceTypeVariableTemplateVo deviceTypeVariableTemplateVo){
        return manageDataService.variableUpdate(deviceTypeVariableTemplateVo);
    }

    @DeleteMapping("variableDelete")
    public Result variableDelete(@RequestParam Integer id){
        return manageDataService.variableDelete(id);
    }

}
